package com.example.companybusiness.operationc;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.companybusiness.R;

import java.util.List;

public class StarBrandAdapter extends RecyclerView.Adapter<StarBrandAdapter.MyAdapter> {
    private Context mContext;
    private List<StartBrandAdapterBean> dataList;

    public StarBrandAdapter(Context mContext) {
        this.mContext = mContext;
    }

    public void setDataList(List<StartBrandAdapterBean> dataList) {
        this.dataList = dataList;
    }

    @NonNull
    @Override
    public MyAdapter onCreateViewHolder(@NonNull  ViewGroup parent, int viewType) {
        return new MyAdapter(LayoutInflater.from(mContext).inflate(R.layout.star_brand_adpter,null));
    }

    @Override
    public void onBindViewHolder(@NonNull  StarBrandAdapter.MyAdapter holder, int position) {
        holder.icon.setImageResource(dataList.get(position).getIcon());
        holder.name.setText(dataList.get(position).getName());
        holder.company.setText(dataList.get(position).getCompany());
        holder.name.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mListener!=null){
                    mListener.onStarclick(position);
                }
            }
        });
    }

    @Override
    public int getItemCount() {
        return dataList!=null?dataList.size():0;
    }

    class MyAdapter extends RecyclerView.ViewHolder{
        ImageView icon;
        TextView name;
        TextView company;
        public MyAdapter(@NonNull  View itemView) {
            super(itemView);
            icon=itemView.findViewById(R.id.star_brand_icon);
            name=itemView.findViewById(R.id.star_brand_name);
            company=itemView.findViewById(R.id.star_brand_company);
        }
    }

    private onStarItemClick mListener;

    public void setmListener(onStarItemClick mListener) {
        this.mListener = mListener;
    }

    public interface onStarItemClick{
        void onStarclick(int position);
    }
}
